//
//  EncryptModle.m
//  LuoGe
//
//  Created by 喻贵华 on 15/9/22.
//  Copyright © 2015年 喻贵华. All rights reserved.
//

#import "EncryptModle.h"
#import"NSString+Password.h"
#import "NSString+Helper.h"
@implementation EncryptModle

-(NSString *)getsign:(NSDictionary *)parmars{
    NSArray *keyary=[parmars allKeys];
    NSSortDescriptor *descriptor = [NSSortDescriptor sortDescriptorWithKey:nil ascending:YES];
    NSArray *descriptors = [NSArray arrayWithObject:descriptor];
    NSArray *keyarysort=[keyary sortedArrayUsingDescriptors:descriptors];
    NSMutableString *sign=[NSMutableString string];
    for (NSUInteger i=0; i<keyarysort.count; i++) {
        [sign appendString:[NSString stringWithFormat:@"%@=%@&",keyarysort[i],parmars[keyarysort[i]]]];
    }
   [sign appendString:[NSString stringWithFormat:@"key=%@",DTCloudKitAppKey]];
    return [sign MD5];
}
-(NSDictionary *)EncryGetDeviceConfigList:(NSDictionary *)info
{
    long long timestamp=time(NULL);
    NSString *time=[NSString
                    stringWithFormat:@"%lld",timestamp ];
    NSString *sign= [self getsign:@{@"productId":DTCloudKitAppId,@"mac":MAC,@"rtime":time,@"version":VERSION,@"uid":EXRACT_OBJECT(UID),@"token":EXRACT_OBJECT(TOKEN)}];
    return @{@"productId":DTCloudKitAppId,
             @"mac":MAC,
             @"rtime":time,
             @"version":VERSION,
             @"sign":sign,
             @"uid":EXRACT_OBJECT(UID),
             @"token":EXRACT_OBJECT(TOKEN)};
}
@end
